package loginutils

import (
	"errors"
	"hft/e"
	"hft/global"
	"hft/tools"
)

// 生成token
func GenerateToken(baseClaims tools.BaseClaims, userType string) (token string, err error) {
	var ep string
	var bf string
	switch userType {
	case "admin":
		ep = global.OC_CONFIG.LoginTime.AdminEP
		bf = global.OC_CONFIG.LoginTime.AdminBF
	case "site":
		ep = global.OC_CONFIG.LoginTime.SiteEP
		bf = global.OC_CONFIG.LoginTime.SiteBF
	case "nor":
		ep = global.OC_CONFIG.LoginTime.NorEP
		bf = global.OC_CONFIG.LoginTime.NorBF
	}
	j := tools.NewJWT() //获取新的秘钥
	var claims = j.CreateClaims(baseClaims, ep, bf)
	if token, err := j.CreateToken(claims); err != nil {
		return "", errors.New(e.InValidToken)
	} else {
		return token, nil
	}
}
